﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Lm.Common.ExtensionMethods;

namespace Lm.Common.Auth.Client
{
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            InitializeComponent();
        }

        private void LoginForm_Load(object sender, EventArgs e)
        {
            this.MinimumSize = this.Size;
            this.MaximumSize = this.Size;
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (this.txtAccount.Text.IsNullOrBlank())
            {
                MessageBox.Show("必须输入用户名");
                this.txtAccount.Focus();
                return;
            }
            if (this.txtPassword.Text.IsNullOrBlank())
            {
                MessageBox.Show("必须输入密码");
                this.txtPassword.Focus();
                return;
            }
            try
            {
                var response = Root.ClientRoot.NetClient.Request(
                    new Lm.Common.Auth.Common.RequestResponseModel.Login.Request()
                    {
                        Account = this.txtAccount.Text.Trim(),
                        Password = this.txtPassword.Text.Trim(),
                    });
                Root.ClientRoot.LoginInfo.Set(this.txtAccount.Text.Trim(), DateTime.Now, response.Token);
                this.txtAccount.Clear();
                this.txtPassword.Clear();
                this.Close();
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }          
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

      
    }
}
